Agent-based turing complete transactions integrating feedback within a blockchain system

ABSTRACT

This invention relates generally to blockchain implementations and is suited for, but not limited to, use with the Bitcoin blockchain. It can be used for the implementation of automated processes such as device/system control, process control, distributed computing and storage and others. The invention provides a solution which uses a blockchain to control a process executing on a computing resource. In a preferred embodiment, the computing resource, running simultaneously and in parallel to the blockchain, manages a loop-based operation. The computing resource continuously monitors the state of the blockchain as well as any other off-blockchain input data or source. The execution of the loop is influenced by the state of the blockchain. Each iteration of the loop that is executed by the computing resource is recorded in a transaction that is written to the blockchain. It is stored as a hash within the transaction&#39;s metadata. If the computing resource finds a transaction which contains a hash relating to the loop it accesses the relevant portion of code. The loop contains a conditional statement which enables the computing resource to decide which action to take. The condition may be dependent upon the state of the blockchain or any other data source. The action can be any type of action, on or off the blockchain. Thus, the combination of the computing resource and blockchain provide a solution which is (at least partially) Turing-complete.

This invention relates generally to consensus-based electronic ledgers,and in particular to blockchain implementations and technologies. Theinvention is particularly suited, but not limited to, use with theBitcoin blockchain and for applications such as device/system control,process control, distributed computing and storage.

In this document we use the term ‘blockchain’ to include all forms ofconsensus-based electronic, computer-based, distributed ledgers. Theseinclude, but are not limited to blockchain and transaction-chaintechnologies, permissioned and un-permissioned ledgers, shared ledgersand variations thereof. The most widely known application of blockchaintechnology is the Bitcoin ledger, although other blockchainimplementations have been proposed and developed. While Bitcoin may bereferred to herein for the purpose of convenience and illustration, itshould be noted that the invention is not limited to use with theBitcoin blockchain and alternative blockchain implementations andprotocols fall within the scope of the present invention.

A blockchain is a consensus-based, electronic ledger which isimplemented as a computer-based decentralised, distributed system madeup of blocks which in turn are made up of transactions. Each transactionis a data structure that encodes the transfer of control of a digitalasset between participants in the blockchain system, and includes atleast one input and at least one output. Each block contains a hash ofthe previous block to that blocks become chained together to create apermanent, unalterable record of all transactions which have beenwritten to the blockchain since its inception. Transactions containsmall programs known as scripts embedded into their inputs and outputs,which specify how and by whom the outputs of the transactions can beaccessed. On the Bitcoin platform, these scripts are written using astack-based scripting language.

In order for a transaction to be written to the blockchain, it must be“validated”. Network nodes (miners) perform work to ensure that eachtransaction is valid, with invalid transactions rejected from thenetwork. Software clients installed on the nodes perform this validationwork on an unspent transaction (UTXO) by executing its locking andunlocking scripts. If execution of the locking and unlocking scriptsevaluate to TRUE, the transaction is valid and the transaction iswritten to the blockchain. Thus, in order for a transaction to bewritten to the blockchain, it must be i) validated by the first nodethat receives the transaction—if the transaction is validated, the noderelays it to the other nodes in the network; and ii) added to a newblock built by a miner; and iii) mined, i.e. added to the public ledgerof past transactions.

Although blockchain technology is most widely known for the use ofcryptocurrency implementation, digital entrepreneurs have begunexploring the use of both the cryptographic security system Bitcoin isbased on and the data that can be stored on the Blockchain to implementnew systems. These include but are not limited to:

-   -   Storing metadata    -   Implementing digital tokens    -   Establishing contracts that are signed with digital signatures.

It would be highly advantageous if the blockchain could be used forautomated tasks and processes which are not limited to the realm ofcryptocurrency. Such solutions would be able to harness the benefits ofthe blockchain (e.g. a permanent, tamper proof records of events,distributed processing etc) while being more versatile in theirapplications.

One area of current interest within the blockchain community is TuringCompleteness, and specifically how to facilitate Turing Completebehaviour into blockchain technologies, which have been designed torestrict functionality for security reasons.

It is disputed whether Bitcoin scripting language is Turing completebecause it does not natively support complex flow control functionality,for example, loops to occur. One advantage of this restriction is thatthe programs have predictable execution times. Another significantadvantage of limiting the Bitcoin scripts to linear or tree-likedecision tasks is that this avoids infinite loops, which can be used asa means of launching exploits such as a denial of service (DoS or DDoS)attack. As a result of this limitation, Bitcoin scripts are oftenlimited to being used for linear tasks rather than more complexapplications such as the control of automated tasks, device managementetc.

The Ethereum blockchain platform approaches this issue by incorporatinga “built in” Turing complete language called Solidity. This language isnative to the Ethereum platform so that scripts written in Solidity caninclude control flow mechanisms such as loops. However, Ethereum hassuffered from several attacks and exploits.

There also remains a desire within a significant portion of theblockchain community to preserve the use of the limited scriptinglanguages in relation to blockchain technologies due to the securityconcerns mentioned above, and because of the widespread use andfamiliarity of the Script language used by Bitcoin.

Thus, it is desirable to provide a solution which facilitatesTuring-complete functionality such as looping mechanisms and othercomplex control structures to be integrated or combined with blockchainscripts, while avoiding the damaging effects of potential securityweaknesses such as infinite loops. Such a solution would providenumerous benefits including:

-   -   Enabling the automation of complex blockchain-related        transactions;    -   Controlling the metadata stream that is recorded onto the        Blockchain    -   Extending the functionality and applications of blockchain        platforms which do not rely on or incorporate purposefully        Turing complete languages

Such an improved solution has now been devised. The present inventionprovides a solution which comprises the novel combination of ablockchain coupled with a parallel computing resource which enables theemulation, simulation and/or incorporation of loops and otherTuring-complete functionality outside the typical blockchain script. Inturn, this facilitates numerous applications for automated tasksrelating to, for example, distributed data storage, distributedcomputing and the control of drones, or any IoT (Internet of Things)devices. Such applications may include using the blockchain for metadatastorage, managing digital tokens and establishing contracts.

Thus, in accordance with the present invention there is provided asolution as defined in the appended claims. In accordance with theinvention there may be provided a (process) control method andcorresponding system. The invention may be referred to as ablockchain-implemented control method/system. It may control anautomated task or process.

The invention may be arranged to use a blockchain to emulate/simulateTuring completeness. Additionally or alternatively, the invention mayenable applications which involve Turing complete control mechanisms tobe executed on a blockchain platform.

Additionally or alternatively, the invention may be described as amethod or system arranged to use a blockchain and/or one or moreblockchain transactions to control a process executing on an off-blockcomputing resource. Thus, the invention comprises an arrangement whereindistinct computing components, which are functionally and architecturaldifferent from each other, are arranged to interact so as to provide anovel technical result. The interaction of the different computingsystems (computing resource and blockchain) results in a highly powerfulcontrol solution.

From the perspective of the computing resource, the invention providesthe advantage of a permanent, tamper-proof record of the execution ofthe program. From the blockchain perspective, the invention provides animproved blockchain implementation because it enables Turing-completebehaviour to be at least partially simulated via use of the blockchain,which in turn enables more functionally complex blockchain-basedapplications to be deployed. This is all achieved while maintaining theuse of the limited scripting language for the blockchain transactions.The scripting language may be limited (restricted) in that its design orimplementation prevents or at least does not natively support theincorporation of complex control flow mechanisms such as loops into codewritten in that language. The instructions set of the language i.e. the“commands” or “op-codes” that the programmer can use, may be arrangedsuch that it does not include commands for complex flow controlmechanisms.

The blockchain may be associated with, or used with, a blockchainprotocol which comprises a limited language. This may be a scriptinglanguage. The invention may extend the functionality of a limitedscripting language for the execution of tasks using the blockchain.

The invention may use the state of the blockchain to execute aloop-based process. The loop-based process may be performed on acomputing resource operating in parallel to the blockchain network. Thecomputing resource may be distinct from (not part of) the blockchainnetwork. The computing resource may be referred to as an “oracle” or a“bot”.

This enables the blockchain protocol to utilise a functionally limitedscripting language while allowing control flow mechanisms such aslooping mechanisms to be implemented off the blockchain. This novelcombination enhances the versatility of blockchain technology whilepreserving security.

The method may comprise the steps of:

-   -   executing a loop on a computing resource; and    -   using the state of the blockchain to influence the execution of        the loop.

Additionally or alternatively, the invention may comprise the step ofimplementing a Turing machine using a blockchain with code referencesprovided in one or more transactions and/or blocks (of transactions).

The computing resource may be any processor-based device or system. Itmay, for example, be a server or plurality of servers. It may be astandalone or a distributed resource. The blockchain may be the Bitcoinblockchain or any other blockchain-related platform. The blockchain maybe a consensus-based distributed ledger.

Information relating to at least one iteration of the loop may be storedin a transaction on the blockchain. The information may be stored asmetadata in the transaction. The loop may contain a “If condition thenaction” (ICTA) instruction.

The method may further comprise the step of generating a cryptographichash of code relating to the loop and, preferably, storing thecryptographic hash within a transaction on the blockchain. The code maybe a code block containing a control flow statement, such as an “Ifcondition then action” statement. The code block may be a portion ofcode such as a whole or partial subroutine (e.g. function, method,procedure). The control flow statement may control or influence how theloop executes e.g. number of iterations.

The computing resource may be arranged to monitor the state of theblockchain for a transaction comprising a cryptographic hash of coderelating to the loop.

The method may further comprise the steps:

for each iteration of the loop:evaluating a condition and performing at least one action based on theoutcome of the evaluation, wherein the at least one action comprises:

-   -   causing at least one transaction to be written to the        blockchain; and/or    -   causing an off-blockchain action to be performed.

The condition may be used to monitor any value, signal or input,regardless of where, how or by whom it is generated, either on or offthe blockchain. The condition may relate to data received, detected orgenerated by the computing resource; and/or the state of the blockchain.The condition may be described as a “trigger”. It may be or relate to aparticular state of the blockchain, or an event detected off-block (e.g.a date or temperature reading, etc.), or a combination of both.

The Action may include sending a signal to cause an event off clock, orbroadcasting a new transaction, or a combination of both. The index maybe maintained (i) off block within the computing resource (“Manager”) ormay be (ii) a value stored within a transaction that is then broadcast.

(i) and (ii) represent two alternative ways to maintain the controldata.

The computing resource may be arranged to monitor:

-   -   the state of the blockchain; a value generated or received by        the computing resource; and/or a data or signal source provided        off the blockchain.

The method may comprise the steps of:

i) using the blockchain as a storage component for data, instructions ora pointer to data and/or instructions; andii) using a computing resource as a control flow management componentfor a Turing complete process, the computing resource being arranged toexecute a looping mechanism.

Thus, the blockchain may serve as the non-erasable tape of a Turingmachine. The computing resource may serve to control the flow ofexecution of the process, implementing a loop and extending thefunctionality of the scripting language.

The method may further comprise the step of restarting (respawning) theloop at a specified iteration. The loop may be restarted if thecomputing resource finds a predetermined hash of a portion of code in atransaction within the blockchain. The portion of code may relate to thebody of the loop. It may comprise an ICTA statement.

The computing resource may respawn the loop at each iteration. This maybe performed in a variety of ways. For example, a code block for theloop may be:

hard-coded into the computing resource itself;stored in a private or publicly available file;stored as an entry on a private or public hash table file;or a combination of the above.

The code block may be static with hard-coded variables or may be staticbut contain parameter(s) that can be populated. The parameters may besingle values of any data format, or could be small chunks of code, orcombinations of the above. The parameters may be populated by retrievingthem directly from metadata in a transaction (e.g. bitcoin transaction)or from an external source such as an internal database or aprivate/public file or hash table or any combination of the above.Pointers to the external source of parameter values may be stored inmetadata in a transaction.

The information relating to the iteration may be specified usingmetadata provided within, or in association with, the transaction.

The computing resource may comprise or be in communication with aregistry, database, repository or other storage facility which enablesthe computing resource to access a pre-stored version of the subroutine.The registry may store:

i) a cryptographic hash of code relating to the loop; andii) information indicative of a location where a copy of the code can beaccessed from. The method may further comprise the step of using ablockchain transaction to update code for the loop so that the existingcode is replaced with new code. Preferably, the transaction is amulti-signature P2SH transaction. A hash of the existing code and a hashof the new code may be stored.

The invention also provides a system for implementing any embodiment ofthe method described above.

The invention may provide a computer-based system. The system may bearranged to use a blockchain to control a process executing on acomputing resource. Additionally or alternatively, the system may bearranged to use (interact with) a blockchain to simulate or emulateTuring completeness, and/or enable tasks (applications) involvingcontrol flow structures such as loops to be performed via theblockchain.

The system may comprise:

-   -   a blockchain; and    -   a computing resource arranged to execute a loop such that        execution of the loop is influenced by state of the blockchain.

Information relating to at least one iteration of the loop is stored ina transaction on the blockchain. Preferably, the information is storedas metadata in the transaction.

Preferably, the computing resource is arranged to generate acryptographic hash of code relating to the loop. Preferably, thecryptographic hash is stored within a transaction on the blockchain.Additionally or alternatively, the computing resource is arranged tomonitor the state of the blockchain for a transaction comprising acryptographic hash of code relating to the loop.

Preferably, for each iteration of the loop: a condition is evaluated andat least one action is performed based on the outcome of the evaluation;the at least one action comprising:

-   -   causing at least one transaction to be written to the        blockchain; and/or    -   causing an off-blockchain action to be performed.

The condition may relate to data received, detected or generated by thecomputing resource; or the state of the blockchain.

The computing resource may be arranged to monitor:

-   -   the state of the block chain;    -   a value generated or received by the computing resource; and/or    -   a data or signal source provided off the blockchain;

The blockchain may serve as a storage component for data, instructionsor a pointer to data and/or instructions. The computing resource mayserve as a control flow management component for a Turing completeprocess, the computing resource being arranged to execute a loopingmechanism. The blockchain may be arranged for operation with a limitedlanguage such as, for example, the Bitcoin Script language.

The loop may be restarted at a specified iteration if the computingresource finds a predetermined hash of a portion of code in atransaction within the blockchain. The information relating to theiteration may be specified using metadata provided within, or inassociation with, the transaction.

The computing resource may comprise or be in communication with aregistry which enables the computing resource to access a pre-storedversion of the subroutine. The registry may store:

i) a cryptographic hash of code relating to the loop; andii) information indicative of a location where a copy of the code can beaccessed from.

The system may be configured to use a blockchain transaction to updatecode for the loop so that the existing code is replaced with new code.Preferably, the transaction is a multi-signature P2SH transaction.Preferably, the system is arranged to store a hash of the existing codeand a hash of the new code.

Any feature described in relation to one aspect or embodiment of theinvention may also be applicable in respect of any other aspect orembodiment. For example, any feature described in relation to the methodmay also be used in relation to the system, and vice versa.

These and other aspects of the present invention will be apparent fromand elucidated with reference to, the embodiment described herein. Anembodiment of the present invention will now be described, by way ofexample only, and with reference to the accompany drawings, in which:

FIG. 1 shows an illustrative use of the Blockchain as a non-erasabletape for the Turing machine.

FIG. 2 illustrates a subroutine that can be used by the Manager toimplement a repeat loop in conjunction with a blockchain.

FIG. 3 shows an example of a ICTA (If Condition Then Action) code blockwhich can be used in accordance with an embodiment of the invention.

FIG. 4 shows the bitcoin commands that allow users to move data in andout of the alternative stack, in accordance with an embodiment of theinvention.

FIG. 5 shows the Manager's code registry in accordance with anembodiment of the invention.

FIG. 6 shows metadata associated with the Manager's code block, inaccordance with an embodiment of the invention.

FIG. 7 shows metadata associated with the output at a particulariteration of the Manager's loop, in accordance with an embodiment of theinvention.

FIG. 8 shows a transaction script and metadata, in accordance with anembodiment of the invention.

FIG. 9 shows an illustrative Manager software patching verification andaudit trail.

FIG. 10 shows an illustrative use of the present invention, and shows anembodiment of a vote counting bot's repeat loop in pseudocode.

The following describes an illustrative embodiment which uses theBitcoin Blockchain. However, other blockchain protocols andimplementations may be used. The invention is not limited in thisregard.

The present invention addresses the problem of how to facilitate TuringCompleteness on an operationally limited blockchain platform (ie onewhich uses a scripting language that does not support complex controlmechanisms), and therefore extend the uses or applications to which theblockchain can be put. Marvin Minsky (Minksy et al., Computation: Finiteand Infinite Machines, Prentice Hall, Inc, 1967) described how anon-erasable tape can be used to implement a machine that is Turingcomplete, and is able to execute any algorithm that can also be executedon a Universal Turing machine.

The present invention comprises a computing resource which operates inconjunction with the blockchain, using it as the non-erasable tape inthe implementation of a Turing machine. This computing resource runs inparallel with the blockchain network, overseeing and handling theexecution of a looping process. The looping process is designed toperform a given task such as, for example, the automation of a processor control of a device or system (for example control of an IoT device).The parallel resource monitors the state of the blockchain and can causetransactions to be written to the blockchain. Therefore, it may bereferred to herein as “the Manager’ for convenience of reference.

Features and advantages of the invention include:

-   -   Enabling the Blockchain to serve as a non-erasable tape of the        Turing Machine    -   The function and implementation of a computer-based monitoring        and management component (Manager) which operates alongside the        Blockchain    -   Using the Manager as the instruction table of the Turing Machine    -   Managing the Manager using a code registry    -   Transaction metadata relating to the Manager's code and        respawning of the loop    -   Using digital signatures to implement software updates to the        Manager    -   A special implementation of the Manager using an alternate        Blockchain.

The Blockchain as the Turing Machine's Non-Erasable Tape

With reference to FIG. 1, the present invention utilises the Blockchainas a non-erasable tape of the Turing Machine, with the followingdefinitions and features:

-   -   1. the Blockchain acts as the tape of the Turing Machine. Each        transaction in the Blockchain represents a cell on the tape.        This cell can contain symbols from a finite alphabet.    -   2. The tape head can read information from the blocks that have        already been written onto the Blockchain.    -   3. The tape head can write new blocks, containing many        transactions, to the end of the Blockchain. However, they cannot        write onto blocks that already exist. As such, the Blockchain        tape is non-erasable.    -   4. Metadata for each transaction can be stored as part of a        multi-signature pay-to-script-hash (P2SH) transaction.

An important function of the Manager is to act as an agent that monitorsthe current state of the Blockchain. It can also receive a signal orinput from any off-block source. Depending on the Blockchain stateand/or a received input, the Manager may perform certain actions. Themanager decides which action(s) are to be performed. These may or maynot involve actions in the ‘real world’ (i.e. off block) and/or actionson the Blockchain (such as creating and broadcasting new transactions).The action that the Manager takes may be triggered by the Blockchainstate or by some off-block input. The Manager may also decide on thenext set of transactions to be broadcast to the Bitcoin network, andsubsequently written to the Blockchain.

The Manager's action(s) run in parallel and simultaneously to theBitcoin network. In a sense, this extends the function of thebehaviourly-restricted Bitcoin script. This continuous monitoringimplements the ‘loop’ control-flow constructs making the combinedManager and Blockchain system Turing Complete.

The Manager as the Turing Machine's Instruction Table

In accordance with an embodiment of the invention, the Turing Machineincludes two stacks:

-   -   Data stack: This is represented by the Blockchain as described        above.    -   Control stack: This is represented by the Manager function. This        stores information relating to the repeat control-flow function.

The separation of the control stack from the data stack provides theadvantage of preventing infinite loops from occurring within theblockchain (e.g. Bitcoin) core. This in turn mitigates denial-of-serviceattacks on the Bitcoin system.

The Manager manages and runs subroutines that are able to loop via anytype of loop construct (e.g. FOR-NEXT; WHILE, REPEAT UNTIL; etc). Anillustrative embodiment described herein includes a process using oneexample of the ‘repeat’ construct (see FIG. 2). The user specifies theindex (i) and the limit (J). These represent the current iterationnumber (typically counted starting from 0) and the total number ofiterations of the repeat loop respectively.

For each iteration:

-   -   1. The Index increments by 1. For the exit condition, the        iterations will stop when the index reaches the limit    -   2. A code block containing an “if condition then action” (ICTA)        statement is executed; the action may be any action on or off        the blockchain;    -   3. A cryptographic hash of this subroutine is computed. This can        be stored in the Blockchain as part of a transaction (Tx). Since        the hash is unique to each code block, it will enable        verification of which code has been used

Thus, the body of the loop includes a code block. Each code blockcontains a “If condition then action” (ICTA) statement (see FIG. 3).This monitors the current state of the Blockchain for transactionsmatching the:

-   -   Start or triggering condition (e.g when a particular Bitcoin        address reaches 10 BTC).    -   Repeat condition (i.e. a metadata or hash associated with the        previous iteration).    -   Stop condition (i.e. last iteration of the loop).

The ICTA statement enables the Manager to decide on the next transactionto make, based on the current state of the blockchain. Making the nexttransaction involves broadcasting the transaction onto the Bitcoinnetwork, and writing the new transaction onto the Blockchain. This actsas a record that this iteration has been executed. Once the transactionhas been written onto the Blockchain, the Manager will subsequently findthat the previous iteration has been executed and written onto theBlockchain, and will execute the next iteration. The latter continuesuntil the repeat loop exits when the index (i) reaches the limit (J)specified in the code block.

Each transaction is saved in the blockchain in a way that can be reused.In a Bitcoin implementation, each signature in a transaction is appendedwith a SIGHASH flag. This flag can take on different values, eachindicating whether other parts of the transaction can be amended withoutinvolvement of the owner of this signature. A reusable transaction hasthe SIGHASH flag ‘SigHash_AnyoneCanPay’ in one of the transactioninputs. This permits anyone to contribute to the inputs of thetransaction. This parameter enables the Manager's ICTA function to beexecuted and repeated multiple times and with different inputs. Use ofthe function can be restricted to authorised parties—for example, viacopyright of the reusable transaction.

The ‘If condition’ section of the ICTA code block can monitor any typeof condition. This is similar to other programming languages (e.g. C,C++, Java) and not limited to information stored on the Blockchain. Someexample conditions are listed below:

-   -   Monitor the date and time (i.e. when a certain date and time are        reached).    -   Monitor the weather (i.e. when the temperature is below 10° C.        and it is raining).    -   Monitor social media (i.e. when I've received a message from my        friend).    -   Monitor conditions of a contract or a trust (i.e. when company A        buys company B).    -   Monitor news and events (i.e. when soccer team A wins a match).    -   Monitor information from the internet of things (i.e. when a        light bulb needs replacing).    -   Monitor data from a mobile/wearable device (i.e. when a wearable        step tracking device counts 10000 steps).    -   Monitor results from cloud computing (i.e. when a computation is        completed and results are received).    -   Monitor remote data storage (i.e. if file still exists        remotely).

The ‘Then action’ section of the ICTA code block can execute a number ofactions. The invention is not limited with regard to the number or typeof actions that can be taken. The action is not limited to a transactionon the Blockchain, although a transaction containing metadata related tothe action may be written on the Blockchain.

The metadata can be of any form specified by the Manager. However, inaccordance with one embodiment of the invention, the metadata may storea hyperlink to a file containing more data or instructions relating tothe action. The metadata may store both a hyperlink to a hash tablecontaining more data or instructions relating to the action along with ahash of the action that acts as the loop-up key for the hash table. Anembodiment may use a link similar in style to the BitTorrent's magnetURL format.

A list of example actions is listed below.

-   -   Bitcoin transactions (i.e. send Bitcoins to a particular        address).    -   Social media (i.e. send a message to a friend).    -   Trading (i.e. sell X shares).    -   Internet of things (i.e. switch off a light bulb).    -   Commerce (i.e. purchase an item online).    -   Online services (i.e. pay a monthly fee or pay for services        requested using Bitcoin).

As the invention is not limited in respect of the nature, type or numberof actions performed, it provides a highly versatile solution which maybe applied to great advantage over a wide range of applications.

The Manager's control stack can be implemented in a number of ways thatare specific to the needs of each user. For example, the repeat loop ofthe control stack can be based on any Turing Complete language. Onepossible choice of language is the Forth style stack-based language. Anadvantage of using this language is that it keeps the control stackconsistent in programming style with the Bitcoin scripts which arealready known and in wide usage.

Using the Bitcoin Script's Alternate Stack as a Data Storage Space

The Bitcoin script contains commands, also called op codes, which enableusers to move data onto an alternative stack, known as the ‘alt stack’.

The op codes are:

-   -   OP_TOALTSTACK—which moves data from the top of the main stack        onto the top of the alt stack.    -   OP_FROMALTSTACK—which moves data from the top of the alt stack        to the top of the main stack (See FIG. 4).

This enables data from intermediate steps of calculations to be storedin the alt stack, similar to the ‘memory’ function which allows data tobe stored on the calculator. In accordance with an illustrativeembodiment of the invention, the alt stack is used for configuringbitcoin scripts to solve small computation tasks and returning theresults in the computation.

Using a Code Register to Manage the Manager

The Manager also manages a registry of all the codes that it owns andruns. This registry is structured like a lookup table or dictionary thatmaps a specific key to a specific value (see FIG. 5). The key and valuepair is represented by the hash of the code block (Hi) and the IPv6address of where the code is stored respectively. To retrieve the codeblock using the key Hi, the lookup table is used to retrieve theassociated value (this is the location where the code is stored) andretrieves the source code accordingly.

The implementation of the code registry can vary. For example, thelookup table can be implemented using a locally managed list, or a P2Pdistributed hash table. The source code can be stored locally, remotely,or using a decentralized file storage system. This could be implementedwith a magnet URI format or any link format that uses shared zeroknowledge encryption.

Transaction Metadata of the Manager's Code, and Re-Spawning of the Loop

Information required to respawn the Manager's loop at a particulariteration is stored as metadata in the transaction recorded on theBlockchain (see FIG. 6 and FIG. 7).

In this way, a transaction on the blockchain stores or provides accessto information about a given iteration of the loop which is beingexecuted on the Manager. This information can include the values of anyvariables associated with the loop, such as index i, and any othernecessary information such as values for parameters used in the codeblock or location-related data specifying where further requiredinformation can be accessed.

The metadata itself is stored as part of a multi-signaturepay-to-script-hash script (P2SH) in the transaction. See FIG. 8 for thescript's format. The metadata recorded with the transaction also givesthe ability to record an audit trail of how the code has been executedin the past.

There are several ways in which the Manager could respawn the repeatloop code block at each iteration. The code block might be hard-codedinto the Manager itself, or could be stored in a private or publiclyavailable file, or stored as an entry on a private or public hash tablefile, or a combination of the above. The code block could be static withhard-coded variables or could be static but contain parameter(s) thatcan be populated. The parameters could be single values of any dataformat, or could be small chunks of code, or be combinations of theabove. The parameters could be populated by retrieving them directlyfrom metadata in a transaction (e.g. bitcoin transaction) or from anexternal source such as an internal database or a private/public file orhash table or any combination of the above. Pointers to the externalsource of parameter values might be stored in metadata in a transaction.

The following steps provide one example of how the Manager can respawn arepeat loop code block at the ith iteration. In this example, the coderegistry is a hash table whereby the hash values act as look-up keys forthe table and are stored in metadata on transactions.

-   -   1. The Manager monitors the Blockchain for transactions that        contain hashes of the code block that matches entries in the        code registry.    -   2. The Manager finds a transaction that contains the        corresponding hash (Hi).    -   3. The Manager reads the ‘Metadata-CodeHash’, gets the CodeHash        field to get Hi and uses it to retrieve the code (C₁). If        RIPEMD-160(SHA256(C₁)) equals Hi, the code has not been changed        and it is safe to proceed to the next step.    -   4. The Manager reads the ‘Metadata-CodeHash’ which stores the        index I, and respawns the code at the i^(th) iteration. In other        words, the loop is ‘reloaded’ at the appropriate iteration    -   5. The signature of the User is included in the P2SH command to        verify the origin of the metadata.    -   6. The Manager reads the ‘Metadata-OutputHash’ and        ‘Metadata-OutputPointer’ (see FIG. 6) to retrieve the output of        the previous steps, if these data are required for this        iteration of the loop.

Multiple signatures may be required to unlock the transaction (e.g. theUser, the Operating System, the Software Developer and the SoftwareVendor). This enables a digital rights management (DRM) system formanaging the rights to operate the codes by all parties involved in theP2SH transaction.

Updating the Manager's Code

Software updates and patches for code blocks that relate to the Managerare securely authorized using a multi-signature P2SH transaction (seeFIG. 8). The multi-signature transaction records metadata of the old andnew code blocks as shown in FIGS. 8 and 9. This makes a record of thechangeover of the old code to the new code, thereby providing an audittrail of the software update. The Manager needs to store all hashes ofthe old and new blocks of source codes. The hash of the new and oldsource code blocks can be used to verify the integrity of the codefiles.

In accordance with an embodiment of the invention, multiple signaturesare required to unlock the transaction (e.g. the User, the OperatingSystem, the Software Developer and the Software Vendor). This provides aDRM system for managing software updates and patches for codes that areused by the Manager.

Unlike most software, which does not allow software to be updated whileit is running, an advantage of the present invention is that softwareupdates can occur in the middle of executing a loop. This provides adynamic and responsive solution which can be reconfigured in real-timeand with minimal disruption to the process which is being controlled bythe invention.

The information captured on the Blockchain (see FIG. 8 and FIG. 9) canbe used to update to the new code in the middle of a loop, and start thenext iteration step using the output metadata from the previousiteration from the old code.

EXAMPLE USE

The current Bitcoin scripting language does not allow loops to takeplace. This prevents would-be attackers from using Bitcoin payments totrigger continuous and automated actions which would otherwise requireexternal intervention to halt them. However, as the Manager of theinvention continuously monitors information on the Blockchain, thisallows complex automated actions to be performed based on up-to-dateinformation on the Blockchain in a safe manner.

The following illustrates how the Manager's control stack can be used toautomate processes involving an automated and online vote counting bot.It should be noted that this is not restricted to “voting” in the senseof electoral or political voting, but can be used for any application inwhich selection or choice-making is involved. The term “vote” may simplybe used to mean “selection” or “choice” or “indication”.

The vote counting bot is designed to facilitate fair andpseudo-anonymous voting, with the Blockchain recording an unalterable,permanent audit trail of the vote counting process. The vote countingbot is automated using the Manager's control stack and repeat loop (seeFIG. 10). The following scenario illustrates how this operates.

There are 100 voters. If 57 unique “Yes” votes are received before 1Jan. 2016, payments will be released to the Chair, Jason. The votingprocess is divided into two parts:

-   -   Token distribution    -   Counting

For the token distribution, 100 voting tokens are distributed to eachauthorized voter. Each token is represented by a (Bitcoin) public keyand private key pair. This is distributed to each voter using a secretexchange protocol. Each Bitcoin public key and address is loaded with asmall amount of Bitcoin representing one vote. The bot keeps the list ofpublic key associated with each authorized token and makes this listpublic before voting begins. To ensure voting cannot be rigged and thatvoting is anonymised, the list of private keys and the mapping betweenthe voter's identity and their token is destroyed (i.e. never stored).

Having an anonymized and pre-authorized list of addresses provides otherimportant benefits. It ensures that only those who are authorized cancast a valid vote. It can also facilitate the exclusion of any unwantedvotes that originate from particular addresses (e.g. spammers,disqualified voters) without compromising the identity of the voters. Toimplement the counting process, the Manager runs a repeat loop. The listof addresses are be kept in the bitcoin script, and transferred to thealternate stack for storage of data. Once an address has been counted,it is removed from the alternate stack and no longer added to the nexttransaction. The repeat loop stops when the list of address becomesempty.

Instead of using the integer index i to keep track of where the loop iscurrently at, the vote bot Manager uses it to store the intermediatevalue of the vote count. This ensures that the intermediate value ofvote count is stored in the Blockchain. This provides an audit trail,and shows that the vote counting process is fair.

If the amount of unique “Yes” votes received reaches 57, the agreedamount of Bitcoins will be paid to Jason's account. The cryptographichash of the vote counting script, and the IPv6 address of where thisscript is stored, are released to the public. This means that the publichas enough information to perform a recount, and ensure the votecounting process is fair and correct.

It should be noted that the above-mentioned embodiments illustraterather than limit the invention, and that those skilled in the art willbe capable of designing many alternative embodiments without departingfrom the scope of the invention as defined by the appended claims. Inthe claims, any reference signs placed in parentheses shall not beconstrued as limiting the claims. The word “comprising” and “comprises”,and the like, does not exclude the presence of elements or steps otherthan those listed in any claim or the specification as a whole. In thepresent specification, “comprises” means “includes or consists of” and“comprising” means “including or consisting of”. The singular referenceof an element does not exclude the plural reference of such elements andvice-versa. The invention may be implemented by means of hardwarecomprising several distinct elements, and by means of a suitablyprogrammed computer. In a device claim enumerating several means,several of these means may be embodied by one and the same item ofhardware. The mere fact that certain measures are recited in mutuallydifferent dependent claims does not indicate that a combination of thesemeasures cannot be used to advantage.

1. A method of using a blockchain to control a process executing on acomputing resource, the method comprising: executing a loop on thecomputing resource; and using the state of the blockchain to influencethe execution of the loop.
 2. A method according to claim 1, whereininformation relating to at least one iteration of the loop is stored ina transaction on the blockchain.
 3. A method according to claim 2,wherein the information is stored as metadata in the transaction.
 4. Amethod according to claim 1, and further comprising generating acryptographic hash of code relating to the loop and storing thecryptographic hash within a transaction on the blockchain.
 5. A methodaccording to claim 1, wherein the computing resource is arranged tomonitor the state of the blockchain for a transaction comprising acryptographic hash of code relating to the loop.
 6. A method accordingto claim 1, the method further comprising: for each of at least aplurality of iterations of the loop: evaluating a condition andperforming at least one action based on the outcome of the evaluation,wherein the at least one action comprises: causing at least onetransaction to be written to the blockchain; and/or causing anoff-blockchain action to be performed.
 7. A method according to claim 6,wherein the condition relates to: data received, detected or generatedby the computing resource; or the state of the blockchain.
 8. A methodaccording to claim 1, wherein the computing resource is arranged tomonitor: the state of the block chain; a value generated or received bythe computing resource; and/or a data or signal source provided off theblockchain.
 9. A method according to claim 1, further comprising: i)using the blockchain as a storage component for data, instructions or apointer to data and/or instructions; and ii) using a computing resourceas a control flow management component for a Turing complete process,the computing resource being arranged to execute a looping mechanism.10. A method according to claim 1, and further comprising: restartingthe loop at a specified iteration if the computing resource finds apredetermined hash of a portion of code in a transaction within theblockchain.
 11. A method according to claim 10, wherein informationrelating to the iteration is specified using metadata provided within,or in association with, the transaction.
 12. A method according to claim1, wherein code for the loop is: hard-coded into or on the computingresource; stored in a private or publicly available file; stored as anentry on a private or public hash table file; and/or a static code blockwith hard-coded variables or at least one parameter.
 13. A methodaccording to claim 1 wherein code for the loop is associated with orcomprises at least one parameter which is: populated, initialized orinstantiated with a single value of any data format; a portion of code;retrieved from metadata in a blockchain transaction or from an sourceexternal to the computing resource; retrieved from a database, or aprivate or public file or hash table; and/or populated using valueswhich are accessed using at least one pointer to a data source, whereinthe at least one pointer is stored as metadata in a transaction on theblockchain.
 14. A method according to claim 1, wherein the computingresource comprises or is in communication with a registry which enablesthe computing resource to access a pre-stored version of a subroutinecomprising execution of the loop.
 15. A method according to claim 14,wherein the registry stores: i) a cryptographic hash of code relating tothe loop; and ii) information indicative of a location where a copy ofthe code can be accessed from.
 16. A method according to claim 1,further comprising: using a blockchain transaction to update existingcode for the loop so that the existing code is replaced with new code;and wherein the transaction is a multi-signature P2SH transaction.
 17. Amethod according to claim 16 and further comprising storing a hash ofthe existing code and a hash of the new code.
 18. A computer-basedsystem arranged to use a blockchain to control a process executing on acomputing resource, the system comprising: a blockchain; and a computingresource arranged to execute a loop such that execution of the loop isinfluenced by state of the blockchain.
 19. A system according to claim18, wherein information relating to at least one iteration of the loopis stored in a transaction on the blockchain; wherein the information isstored as metadata in the transaction.
 20. A system according claim 18,wherein the computing resource is arranged to: i) generate acryptographic hash of code relating to the loop and storing thecryptographic hash within a transaction on the blockchain; and/or ii)monitor the state of the blockchain for a transaction comprising acryptographic hash of code relating to the loop.
 21. A system accordingto claim 18, wherein for each of at least a plurality of iterations ofthe loop: a condition is evaluated and at least one action is performedbased on the outcome of the evaluation; the at least one actioncomprising: causing at least one transaction to be written to theblockchain; and/or causing an off-blockchain action to be performed. 22.A system according to claim 21, wherein the condition relates to: datareceived, detected or generated by the computing resource; or the stateof the blockchain.
 23. A system according to claim 18, wherein thecomputing resource is arranged to monitor: the state of the block chain;a value generated or received by the computing resource; and/or a dataor signal source provided off the blockchain.
 24. A system according toclaim 18, wherein: i) the blockchain serves as a storage component fordata, instructions or a pointer to data and/or instructions; and ii) thecomputing resource serves as a control flow management component for aTuring complete process, the computing resource being arranged toexecute a looping mechanism.
 25. A system according to claim 19, whereinthe loop is restarted at a specified iteration if the computing resourcefinds a predetermined hash of a portion of code in a transaction withinthe blockchain.
 26. A system according to claim 25 wherein theinformation relating to the iteration is specified using metadataprovided within, or in association with, the transaction.
 27. A systemaccording to claim 18, wherein the computing resource comprises or is incommunication with a registry which enables the computing resource toaccess a pre-stored version of a subroutine comprising execution of theloop.
 28. A system according to claim 27 wherein the registry stores: i)a cryptographic hash of code relating to the loop; and ii) informationindicative of a location where a copy of the code can be accessed from.29. A system according to claim 18, wherein the system is configured to:use a blockchain transaction to update existing code for the loop sothat the existing code is replaced with new code; and wherein thetransaction is a multi-signature P2SH transaction.
 30. A systemaccording to claim 29 wherein the system is arranged to store a hash ofthe existing code and a hash of the new code.